package com.javapda.c328r.command;

import java.io.Serializable;

public class ComediaBaudRate implements Serializable {
	public static final ComediaBaudRate BAUDRATE_7200 = new ComediaBaudRate(0xff,0x01);
	public static final ComediaBaudRate BAUDRATE_9600 = new ComediaBaudRate(0xbf,0x01);
	public static final ComediaBaudRate BAUDRATE_14400 = new ComediaBaudRate(0x7f,0x01);
	public static final ComediaBaudRate BAUDRATE_19200 = new ComediaBaudRate(0x5f,0x01);
	public static final ComediaBaudRate BAUDRATE_28800 = new ComediaBaudRate(0x3f,0x01);
	public static final ComediaBaudRate BAUDRATE_38400 = new ComediaBaudRate(0x2f,0x01);
	public static final ComediaBaudRate BAUDRATE_57600 = new ComediaBaudRate(0x1f,0x01);
	public static final ComediaBaudRate BAUDRATE_115200 = new ComediaBaudRate(0x0f,0x01);
	private int firstDivider;
	private int secondDivider;
	private static final long serialVersionUID = 1L;
	private ComediaBaudRate(int _firstDivider, int _secondDivider) {
		this.firstDivider = _firstDivider;
		this.secondDivider = _secondDivider;
	}
	public int getFirstDivider() {
		return firstDivider;
	}
	public void setFirstDivider(int firstDivider) {
		this.firstDivider = firstDivider;
	}
	public int getSecondDivider() {
		return secondDivider;
	}
	public void setSecondDivider(int secondDivider) {
		this.secondDivider = secondDivider;
	}
	
	/**
	 * Baudrate = 14.7456MHz / 2 x (2nd Divider + 1) / 2 x (1st Divider + 1)
	 * @return
	 */
	public double calculateBaudRate() {
		double baudRate = 14.7456 /*MHz*/ / 2 * (secondDivider + 1) / 2 * (firstDivider + 1);
		return baudRate;
	}
	
}
